<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ include file="../session.jsp"%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>${alert}
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header">
			<h2>화제의 제품 조회/수정</h2>
		</div>

		<form id="updateHotProduct" class="form-horizontal" role="form" method="post" action="updateHotProduct.do">
		
			<input type="hidden" name="pId" value="${pId}"/>
			<input type="hidden" name="sId" value="${sId}"/>
			<input type="hidden" name="type" value="${type}"/>
		
			<fieldset>
				<div class="form-group">
					<label for="isDisplay" class="col-md-2 control-label">상태</label>
					<div class="col-md-10">
						<label class="radio-inline"><input type="radio" name="isDisplay" value="1" <c:if test="${cmd.isDisplay == 1}">checked</c:if>> 노출</label>
						<label class="radio-inline"><input type="radio" name="isDisplay" value="0" <c:if test="${cmd.isDisplay == 0}">checked</c:if>> 미노출</label>
					</div>
				</div>
				
				<div class="form-group">
					<label for="isTop" class="col-md-2 control-label">Top 여부</label>
					<div class="col-md-10">
						<label class="radio-inline"><input type="radio" name="isTop" value="1" <c:if test="${cmd.isTop == 1}">checked</c:if>> Y</label>
						<label class="radio-inline"><input type="radio" name="isTop" value="0" <c:if test="${cmd.isTop == 0}">checked</c:if>> N</label>
					</div>
				</div>

				<div class="form-group">
					<label for="brand" class="col-md-2 control-label">브랜드</label>
					<div class="col-md-10">
						<p class="form-control-static">${cmd.idBrandValue}</p>
					</div>
				</div>
				
				<div class="form-group">
					<label for="firstCategory" class="col-md-2 control-label">1차카테고리</label>
					<div class="col-md-10">
						<p class="form-control-static">${cmd.idFirstCategoryValue}</p>
					</div>
				</div>
				
				<div class="form-group">
					<label for="secondCategory" class="col-md-2 control-label">2차카테고리</label>
					<div class="col-md-10">
						<p class="form-control-static">${cmd.idSecondCategoryValue}</p>
					</div>
				</div>

				<div class="form-group">
					<label for="product" class="col-md-2 control-label">제품명</label>
					<div class="col-md-10">
						<p class="form-control-static">${cmd.idProductValue}</p>
					</div>
				</div>
				
				<div class="form-group">
					<label for="promotionText" class="col-md-2 control-label">프로모션 텍스트</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="promotionText" value="${cmd.promotionText}"/>
					</div>
				</div>

				<div class="form-group">
					<label for="start_date" class="col-md-2 control-label">노출시작</label>
					<div class="col-md-10">
						<input type="date" class="form-control" name="start_date" value="${fn:substring(cmd.start_date, 0, 4)}-${fn:substring(cmd.start_date, 4, 6)}-${
								fn:substring(cmd.start_date, 6, 8)}">
					</div>
				</div>
				
				<div class="form-group">
					<label for="end_date" class="col-md-2 control-label">노출종료</label>
					<div class="col-md-10">
						<input type="date" class="form-control" name="end_date" value="${fn:substring(cmd.end_date, 0, 4)}-${fn:substring(cmd.end_date, 4, 6)}-${
								fn:substring(cmd.end_date, 6, 8)}">
					</div>
				</div>

				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<div class="col-md-6">
								<button type="submit" class="btn btn-primary btn-block">수정하기</button>
							</div>
							<div class="col-md-6">
								<button type="reset" class="btn btn-warning btn-block">다시작성</button>
							</div>
						</div>
					</div>
				</div>

			</fieldset>
		</form>
	</div>
	<!-- Javascript -->
	<script src="assets/js/jquery.js"></script>
	<script src="assets/js/bootstrap.min.js"></script>
	<!-- 형식검사 클래스 참조 -->
	<script src="assets/js/string.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#updateHotProduct").submit(function() {
				
				if (!$("input[name='isDisplay']").is(":checked")) {
					alert("전시여부를 선택해 주세요");
					$("input[name='isDisplay']").focus();
					return false;
				}
				
				if (!$("input[name='isTop']").is(":checked")) {
					alert("Top 여부를 선택해 주세요");
					$("input[name='isTop']").focus();
					return false;
				}
				
				if (!$("input[name='promotionText']").val().isValue()) {
					alert("프로모션 텍스트를 입력하세요.");
					$("input[name='promotionText']").focus();
					return false;
				}
				
				if (!$("input[name='start_date']").val().isValue()) {
					alert("노출시작을 입력하세요.");
					$("input[name='start_date']").focus();
					return false;
				}
				
				if (!$("input[name='end_date']").val().isValue()) {
					alert("노출종료를 입력하세요.");
					$("input[name='end_date']").focus();
					return false;
				}
				
				if (!confirm("정말 수정하시겠습니까?")) {
					return false;
				}
				
			});
		});
	</script>
  </body>
</html>